package com.ruoyi.web.studentmanagementsystem.service.impl;

import com.ruoyi.web.studentmanagementsystem.dto.*;
import com.ruoyi.web.studentmanagementsystem.mapper.SysScoreMapper;
import com.ruoyi.web.studentmanagementsystem.pojo.SysScore;
import com.ruoyi.web.studentmanagementsystem.service.ISysScoreService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * ClassName: SysScoreServiceImpl
 * Package: com.ruoyi.web.studentmanagementsystem.service.impl
 * Description:成绩管理 服务实现
 *
 * @Author Mr. o
 * @Create 2023/11/10 14:53
 * @Version 1.0
 */
@Service
public class SysScoreServiceImpl implements ISysScoreService {
    @Resource
    private SysScoreMapper scoreMapper;


    /**
     * 新增保存成绩信息
     *
     * @param score 成绩信息
     * @return
     */
    @Override
    @Transactional
    public void insertScore(ISysScoreDTO score) {
        score.setCreateTime(new Date());
        scoreMapper.insertScore(score);
    }

    /**
     * 删除成绩信息
     *
     * @param studentId 学生ID
     * @return
     */
    @Override
    @Transactional
    public void deleteScore(String studentId) {
        scoreMapper.deleteScore(studentId);
    }

    /**
     * 根据学生ID查询信息
     *
     * @param studentId 学生ID
     * @return
     */
    @Override
    @Transactional
    public List<SysScore> selectScore(String studentId) {
        List<SysScore> s = scoreMapper.selectScore(studentId);
        for (SysScore ss : s) {
            if (ss.getChineseScore() >= 60) {
                System.out.println("及格");
            } else {
                System.out.println("不及格");
            }
        }
        return s;
    }

    /**
     * 修改保存成绩信息
     *
     * @param score 成绩信息
     * @return
     */
    public void updateScore(IISysScoreDTO score) {
        score.setUpdateTime(new Date());
        scoreMapper.updateScore(score);
    }
}
